home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 4896 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.2 KB  |  63 lines

  1. Newsgroups: comp.lang.c
  2. Path: news.sprintlink.net!news1!news
  3. From: rclark@iquest.net (Robert B. Clark)
  4. Subject: Re: Passing Parameters on Exit?
  5. X-Nntp-Posting-Host: ind-009-237-105.iquest.net
  6. Message-ID: <3118e50b.607140@news.iquest.net>
  7. Sender: news@iquest.net (News Admin)
  8. Organization: IQuest Internet, Inc.
  9. X-Newsreader: Forte Agent .99d/16.182
  10. References: <4f69hl$sp2@nic.umass.edu>
  11. Date: Wed, 7 Feb 1996 19:46:36 GMT
  12.  
  13. On 6 Feb 1996 01:05:57 GMT, ksnella@twain.oit.umass.edu (Kenneth A
  14. Snella) wrote:
  15.  
  16. >Is there any way to pass parameters out of a C program?  I'm trying to 
  17. >build a system that exits a C program and executes other programs (not 
  18. >always C ones), but need to pass a couple of important items to the batch 
  19.  
  20. You can return an exit code (errorlevel) from main().  On DOS systems,
  21. this is an integer from 0 to 255.  Let your batch file take advantage of
  22. this in order to determine which program is to be run next.
  23.  
  24. This snippet returns errorlevel 1 when executed:
  25.  
  26. /* foo.c */
  27. int main(void)
  28. {
  29.     /* blah blah blah */
  30.     return 1;
  31. }
  32.  
  33. Your batch file might read something like this:
  34.  
  35. foo
  36. if errorlevel 1 if not errorlevel 2 tw2002 /maint
  37. if not errorlevel 1 echo Returned errorlevel 0--no action requested.
  38.  
  39. >way?  It seems as though a call to the Borland C++ 3.1 function system() 
  40. >would be able to SET an environment parameter, but it doesn't seem to 
  41. >work.  Any suggestions?
  42.  
  43. Using system() to set an environment variable is next to worthless,
  44. because the variable only persists for the duration of *that*
  45. process--upon return to the parent process, the environment table is
  46. restored to its original content.
  47.  
  48. In order to set an evar in the *master* environment table, you'd need to
  49. walk the MCB chain, find the master environment, then write your evar
  50. directly to it (after first making room if needed).  This is fairly
  51. involved, and not always successful or portable across different OEM
  52. versions of DOS.
  53.  
  54. I wrote some code to do this a while ago in Turbo Pascal, but haven't
  55. yet needed to port it to C.  If you'd like to peruse the source code,
  56. grab it from your favorite Garbo site:
  57.  
  58.  19442 Jan 18 01:00 ftp://garbo.uwasa.fi/pc/turbopas/envir10.zip
  59. --
  60. Robert B. Clark <rclark@iquest.net>
  61. "Be wary of strong spirits.  It can make you shoot at tax collectors...
  62. and miss." --RAH
  63.